import os
import sys
import sqlite3
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)
from common.Env import Env

# 连接到 SQLite 数据库
dbPath=Env.getDBPath()
conn = sqlite3.connect(dbPath)
cursor = conn.cursor()

# 创建 books 表
cursor.execute('''
CREATE TABLE IF NOT EXISTS books (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    author TEXT NOT NULL,
    price REAL NOT NULL
)
''')

# 插入示例数据
books = [
    ('Python 编程从入门到实践', 'Eric Matthes', 59.9),
    ('Flask Web 开发实战', '李辉', 49.5)
]
cursor.executemany('INSERT INTO books (title, author, price) VALUES (?,?,?)', books)

# 提交更改并关闭连接
conn.commit()
conn.close()